﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CmpDistToI.cs" company="Luis de la Torre">
//   Copyright Luis de la Torre, unless otherwise indicated
// </copyright>
// <summary>
//   The distance comparer for node i.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace PVRP_SR
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// The distance comparer for node i.
    /// </summary>
    public class CmpDistToI : IComparer<int>
    {
        #region Fields

        /// <summary>
        /// The distance.
        /// </summary>
        private readonly double[] dist;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CmpDistToI"/> class.
        /// </summary>
        /// <param name="dist">
        /// The distance.
        /// </param>
        public CmpDistToI(double[] dist)
        {
            this.dist = new double[dist.Length];
            Array.Copy(dist, this.dist, dist.Length);
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The compare.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int Compare(int x, int y)
        {
            if (this.dist[x] < this.dist[y])
            {
                return -1;
            }

            return this.dist[x] > this.dist[y] ? 1 : 0;
        }

        #endregion
    }
}